<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" th:href="@{/assets/edu/layui/css/layui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/assets/edu/css/css.css}">
    <script type="text/javascript" th:src="@{/assets/edu/js/jquery-1.11.3.js}"></script>

    <script type="text/javascript" th:src="@{/assets/edu/js/md5.min.js}"></script>
    <!-- common.js -->
    <script type="text/javascript" th:src="@{/assets/edu/js/common.js}"></script>

    <script type="text/javascript" th:src="@{/assets/edu/layui/layui.js}"></script>
</head>
<body>
<div class="pad10">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"></label>
                <a href="javascript:;" class="layui-btn ayui-btn-normal bg-blue " data-type="createMajor">
                    <i class="iconfont"></i> 生成专业数据</a>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"></label>
                <a href="javascript:;" class="layui-btn ayui-btn-normal bg-blue " data-type="createSchool">
                    <i class="iconfont"></i> 生成院校数据</a>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"></label>
                <a href="javascript:;" class="layui-btn ayui-btn-normal bg-blue " data-type="createWntdqkHz">
                    <i class="iconfont"></i> 生成投档汇总数据</a>
                <label class="layui-form-label" id="year_mc">年份</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="year">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"></label>
                <a href="javascript:;" class="layui-btn ayui-btn-normal bg-blue " data-type="spiltWntdqk">
                    <i class="iconfont"></i> 拆分投档数据</a>
                <label class="layui-form-label">年份</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="year_split">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"></label>
                <a href="javascript:;" class="layui-btn ayui-btn-normal bg-blue " data-type="spiltRecruitStudentsPlan">
                    <i class="iconfont"></i> 拆分招生计划库数据</a>
                <label class="layui-form-label">年份</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="year_split_rsp">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"></label>
                <a href="javascript:;" class="layui-btn ayui-btn-normal bg-blue " data-type="generateSyzsjhs">
                    <i class="iconfont"></i>更新招生计划库剩余招生计划数</a>
                <label class="layui-form-label">年份</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="year_syzs">
                </div>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['layer', 'laydate'], function () {
        var layer = layui.layer
            , laydate = layui.laydate;
        laydate.render({
            elem: '#year'
            , type: 'year'
            , format: 'yyyy'
            , max: 0
        });
        laydate.render({
            elem: '#year_split'
            , type: 'year'
            , format: 'yyyy'
            , max: 0
        });
        laydate.render({
            elem: '#year_split_rsp'
            , type: 'year'
            , format: 'yyyy'
            , max: 0
        });
        laydate.render({
            elem: '#year_syzs'
            , type: 'year'
            , format: 'yyyy'
            , max: 0
        });
        var active = {
            createMajor: function () {
                layer.confirm('确定要生成专业数据吗?', {
                    btn: ['确定', '取消']
                }, function (index, layero) {
                    major();
                }, function (index) {

                });
            }
            , createSchool: function () {
                layer.confirm('确定要生成院校数据吗?', {
                    btn: ['确定', '取消']
                }, function (index, layero) {
                    school();
                }, function (index) {
                });
            }
            , createWntdqkHz: function () {
                var year = $("#year").val();
                if (year == null || year == "") {
                    layer.msg("请选择生成的年份");
                    return;
                }
                layer.confirm('确定要生成投档汇总数据吗?', {
                    btn: ['确定', '取消']
                }, function (index, layero) {
                    wntdqkHz(year);
                }, function (index) {
                });
            }, spiltWntdqk: function () {
                var year = $("#year_split").val();
                if (year == null || year == "") {
                    layer.msg("请选择拆分的年份");
                    return;
                }
                layer.confirm('确定要拆分"' + year + '"年投档数据吗?', {
                    btn: ['确定', '取消']
                }, function (index, layero) {
                    wntdqk(year);
                }, function (index) {
                });
            }
            , spiltRecruitStudentsPlan: function () {
                var year = $("#year_split_rsp").val();
                if (year == null || year == "") {
                    layer.msg("请选择拆分的年份");
                    return;
                }
                layer.confirm('确定要拆分"' + year + '"年招生计划数据吗?', {
                    btn: ['确定', '取消']
                }, function (index, layero) {
                    recruitStudentsPlan(year);
                }, function (index) {
                });
            },
            generateSyzsjhs: function () {
                var year = $("#year_syzs").val();
                if (year == null || year == "") {
                    layer.msg("请选择要更新的年份");
                    return;
                }
                layer.confirm('确定要更新' + year + '年剩余招生计划数吗?', {
                    btn: ['确定', '取消']
                }, function (index, layero) {
                    generateSyzsjhs(year);
                }, function (index) {
                });
            }
        };
        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

    function major() {
        layer.load();
        $.post("/createData/major", function (res) {
            layer.closeAll();
            if (res.code == 30002) {
                layer.msg(res.msg);
                setTimeout(function () {
                    top.location.href = "/login";
                }, 5000);
            } else if (res.code != 90000) {
                layer.alert(res.msg);
            } else {
                layer.alert("生成成功");
            }
        });
    }

    function school() {
        layer.load();
        $.post("/createData/school", function (res) {
            layer.closeAll();
            if (res.code == 30002) {
                layer.msg(res.msg);
                setTimeout(function () {
                    top.location.href = "/login";
                }, 5000);
            } else if (res.code != 90000) {
                layer.alert(res.msg);
            } else {
                layer.alert("生成成功");
            }
        });
    }

    function wntdqkHz(year) {
        layer.load();
        $.post("/createData/wntdqkhz", {"year": year}, function (res) {
            layer.closeAll();
            if (res.code == 30002) {
                layer.msg(res.msg);
                setTimeout(function () {
                    top.location.href = "/login";
                }, 5000);
            } else if (res.code != 90000) {
                layer.alert(res.msg);
            } else {
                layer.alert("生成成功");
            }
        });
    }

    function wntdqk(year) {
        layer.load();
        $.post("/createData/wntdqk", {"year": year}, function (res) {
            layer.closeAll();
            if (res.code == 30002) {
                layer.msg(res.msg);
                setTimeout(function () {
                    top.location.href = "/login";
                }, 5000);
            } else if (res.code != 90000) {
                layer.alert(res.msg);
            } else {
                layer.alert("拆分成功");
            }
        });
    }

    function recruitStudentsPlan(year) {
        layer.load();
        $.post("/createData/rsP", {"year": year}, function (res) {
            layer.closeAll();
            if (res.code == 30002) {
                layer.alert(res.msg);
                setTimeout(function () {
                    top.location.href = "/login";
                }, 5000);
            } else if (res.code != 90000) {
                layer.alert(res.msg);
            } else {
                layer.alert("拆分成功");
            }
        });
    }

    function generateSyzsjhs(year) {
        layer.load();
        $.post("/createData/syzsjhs", {"year": year}, function (res) {
            layer.closeAll();
            if (res.code == 30002) {
                layer.msg(res.msg);
                setTimeout(function () {
                    top.location.href = "/login";
                }, 5000);
            } else if (res.code != 90000) {
                layer.alert(res.msg);
            } else {
                layer.alert("修改成功");
            }
        });
    }
</script>
</body>
</html>